﻿using System;
using System.Collections.Generic;
using System.Linq;
using Xenta.Entities;
using Xenta.Utils;

namespace Xenta.Operations
{
    /// <summary>
    /// Represents the auditable entity create operation base.
    /// </summary>
    /// <typeparam name="TAuditable">The type of auditable entity.</typeparam>
    public abstract class CreateAuditable<TAuditable> : CreateEntity<TAuditable>
        where TAuditable : class, IAuditableEntity
    {
        protected override void Construct(IUnitOfWork uow, TAuditable entity)
        {
            base.Construct(uow, entity);
            var dtNow = DateTime.UtcNow;
            entity.CreatedOn = dtNow;
            entity.UpdatedOn = dtNow;
        }
    }

    /// <summary>
    /// Represents the auditable entity update operation base.
    /// </summary>
    /// <typeparam name="TAuditable">The type of entity.</typeparam>
    public abstract class UpdateAuditable<TAuditable> : UpdateEntity<TAuditable>
        where TAuditable : class, IAuditableEntity
    {
        protected override void Revise(IUnitOfWork uow, TAuditable entity)
        {
            base.Revise(uow, entity);
            entity.UpdatedOn = DateTime.UtcNow;
        }
    }
}
